<?php
namespace app\fun1219\controller;

use think\Controller;
use think\Request;
use app\fun1219\model\Index as model;

class Index extends Controller
{
    protected $model;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);

        $this->model = new model();
    }

    public function index()
    {
        return $this->fetch();
    }


    public function articleList()
    {
        $data = $this->model->getList();
        
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function article($id)
    {
        $data = $this->model->getContent($id);
        
        if (!$data) {
            throw new \think\exception\HttpException(404, '页面不存在');
        }

        $this->assign('data', $data);
        return $this->fetch();
    }

    public function leacots()
    {
        if (Request::instance()->isAjax()) {
            $param = input('post.');
            // var_dump($param);
            // exit;
            if (empty($param['content'])) {
                return ['code'=>2, 'msg'=>"内容不可为空"];
            }
            if ($this->model->saveLeacots($param)) {
                return ['code'=>1];
            } else {
                return ['code'=>2, 'msg'=>"提交失败, 请稍后重试, 或邮箱联系"];
            }
        }
        return $this->fetch();
    }
}
